import { Tooltip, Typography } from "antd"
import { ColumnGroupType, ColumnType } from "antd/es/table"

import TooltipText from "@/components/common/tooltipText"

const common = (
	newFormat: (arg: string) => string,
	getFromDic: (arg: string, strictlyLabel?: boolean) => any
): Record<string, ColumnGroupType<any> | ColumnType<any>> => ({
	index: {
		key: "index",
		align: "center",
		dataIndex: "serialNumber",
		title: newFormat("common.serial_number"),
		render: (_: any, __: any, index: number) => index + 1,
		width: 80
	},
	merchant: {
		key: "merchant",
		align: "center",
		dataIndex: "merchantId",
		title: newFormat("common.belong_merchant"),
		render: getFromDic("merchantList"),
		width: 120
	},
	accountType: {
		key: "accountType",
		align: "center",
		dataIndex: "accountType",
		title: newFormat("common.account_type"),
		render: getFromDic("accountType", false),
		width: 120
	},
	createdBy: {
		key: "createBy",
		align: "center",
		dataIndex: "createdBy",
		title: newFormat("common.createBy"),
		width: 100
	},
	createdAt: {
		key: "createdAt",
		align: "center",
		dataIndex: "createdAt",
		title: newFormat("common.createAt"),
		width: 200
	},
	updatedBy: {
		key: "updatedBy",
		align: "center",
		dataIndex: "updatedBy",
		title: newFormat("common.last_updateBy"),
		width: 100
	},
	updatedAt: {
		key: "updatedAt",
		align: "center",
		dataIndex: "updatedAt",
		title: newFormat("common.last_updateAt"),
		width: 200
	},
	lastUpdatedBy: {
		key: "updatedBy",
		align: "center",
		dataIndex: "updatedBy",
		title: newFormat("label.lastUpdatedBy"),
		width: 100
	},
	lastUpdatedAt: {
		key: "updatedAt",
		align: "center",
		dataIndex: "updatedAt",
		title: newFormat("agent.last_update_time"),
		width: 200
	},
	remarks: {
		key: "remarks",
		align: "center",
		dataIndex: "remarks",
		title: newFormat("common.remarks"),
		width: 250,
		render: (text: string) => <TooltipText text={text} />
	},
	remark: {
		key: "remark",
		align: "center",
		dataIndex: "remark",
		title: newFormat("common.remarks"),
		width: 200,
		render: (text: string) => <TooltipText text={text} />
	},
	sectionName: {
		width: 140,
		key: "sectionName",
		dataIndex: "sectionName",
		align: "center",
		title: newFormat("common.action_module")
	},
	pageName: {
		width: 120,
		key: "pageName",
		dataIndex: "pageName",
		align: "center",
		title: newFormat("common.action_page")
	},
	optTypeDesc: {
		width: 120,
		key: "optTypeDesc",
		dataIndex: "optTypeDesc",
		align: "center",
		title: newFormat("common.operation_type")
	},
	optFuncDesc: {
		width: 120,
		key: "optFuncDesc",
		dataIndex: "optFuncDesc",
		align: "center",
		title: newFormat("common.action_function")
	},
	optObj: {
		width: 120,
		key: "optObj",
		dataIndex: "optObj",
		align: "center",
		title: newFormat("common.action_ob")
	},
	optUsername: {
		width: 120,
		key: "optUsername",
		dataIndex: "optUsername",
		align: "center",
		title: newFormat("common.action_user_type")
	},
	optUserTypeDesc: {
		width: 120,
		key: "optUserTypeDesc",
		dataIndex: "optUserTypeDesc",
		align: "center",
		title: newFormat("common.action_user_type")
	},
	optIp: {
		width: 120,
		key: "optIp",
		dataIndex: "optIp",
		align: "center",
		title: newFormat("common.updateByIP")
	},
	optBefore: {
		width: 120,
		key: "optBefore",
		dataIndex: "optBefore",
		align: "center",
		title: newFormat("common.action_before"),
		render: (v: string) => {
			if (v && v.includes(";")) {
				const content = v.split(";").map((text, index) => <p key={index}>{text}</p>)
				const text = v.replaceAll(";", "")
				return (
					<Tooltip placement="top" title={content}>
						<Typography.Text style={{ maxWidth: 100 }} ellipsis>
							{text}
						</Typography.Text>
					</Tooltip>
				)
			}
			return v || "-"
		}
	},
	optAfter: {
		width: 120,
		key: "optAfter",
		dataIndex: "optAfter",
		align: "center",
		title: newFormat("common.action_after"),
		render: (v: string) => {
			if (v && v.includes(";")) {
				const content = v.split(";").map((text, index) => <p key={index}>{text}</p>)
				const text = v.replaceAll(";", "")
				return (
					<Tooltip placement="top" title={content}>
						<Typography.Text style={{ maxWidth: 100 }} ellipsis>
							{text}
						</Typography.Text>
					</Tooltip>
				)
			}
			return v || "-"
		}
	},
	actionModule: {
		width: 120,
		key: "actionModule",
		dataIndex: "actionModule",
		align: "center",
		title: newFormat("common.action_module"),
		render: () => newFormat("routes.game.game_venue_manage")
	},
	operationPage: {
		width: 120,
		key: "operationPage",
		dataIndex: "operationPage",
		align: "center",
		title: newFormat("common.action_page")
	},
	operationType: {
		width: 120,
		key: "operationType",
		dataIndex: "operationType",
		align: "center",
		title: newFormat("common.operation_type")
	},
	operationFunction: {
		width: 120,
		key: "operationFunction",
		dataIndex: "operationFunction",
		align: "center",
		title: newFormat("common.action_function")
	},
	merchantName: {
		key: "merchantName",
		align: "center",
		dataIndex: "merchantName",
		title: newFormat("common.belong_merchant"),
		width: 120
	},
	operatorType: {
		width: 120,
		key: "operatorType",
		dataIndex: "operatorType",
		align: "center",
		title: newFormat("common.action_user_type")
	},
	operator: {
		width: 120,
		key: "operator",
		dataIndex: "operator",
		align: "center",
		title: newFormat("common.updateBy")
	},
	operationTarget: {
		width: 120,
		key: "operationTarget",
		dataIndex: "operationTarget",
		align: "center",
		title: newFormat("common.action_ob"),
		render: v => v || "-"
	},
	gameIp: {
		width: 120,
		key: "ip",
		dataIndex: "ip",
		align: "center",
		title: newFormat("common.updateByIP")
	},
	operationBefore: {
		width: 120,
		key: "operationBefore",
		dataIndex: "operationBefore",
		align: "center",
		title: newFormat("common.action_before"),
		render: (v: string) => {
			if (v && v.includes(";")) {
				const content = v.split(";").map((text, index) => <p key={index}>{text}</p>)
				const text = v.replaceAll(";", "")
				return (
					<Tooltip placement="top" title={content}>
						<Typography.Text style={{ maxWidth: 100 }} ellipsis>
							{text}
						</Typography.Text>
					</Tooltip>
				)
			}
			return v || "-"
		}
	},
	operationAfter: {
		width: 120,
		key: "operationAfter",
		dataIndex: "operationAfter",
		align: "center",
		title: newFormat("common.action_after"),
		render: (v: string) => {
			if (v && v.includes(";")) {
				const content = v.split(";").map((text, index) => <p key={index}>{text}</p>)
				const text = v.replaceAll(";", "")
				return (
					<Tooltip placement="top" title={content}>
						<Typography.Text style={{ maxWidth: 100 }} ellipsis>
							{text}
						</Typography.Text>
					</Tooltip>
				)
			}
			return v || "-"
		}
	},
	operationItem: {
		width: 140,
		key: "operationItem",
		dataIndex: "operationItem",
		align: "center",
		title: newFormat("common.action_module")
	},
	operationFunc: {
		width: 120,
		key: "operationFunc",
		dataIndex: "operationFunc",
		align: "center",
		title: newFormat("common.action_function")
	},
	operationIp: {
		width: 120,
		key: "operationIp",
		dataIndex: "operationIp",
		align: "center",
		title: newFormat("common.updateByIP")
	},
	beforeModify: {
		width: 120,
		key: "beforeModify",
		dataIndex: "beforeModify",
		align: "center",
		title: newFormat("common.action_before"),
		render: (v: string) => {
			if (v && v.includes(";")) {
				const content = v.split(";").map((text, index) => <p key={index}>{text}</p>)
				const text = v.replaceAll(";", "")
				return (
					<Tooltip placement="top" title={content}>
						<Typography.Text style={{ maxWidth: 100 }} ellipsis>
							{text}
						</Typography.Text>
					</Tooltip>
				)
			}
			return v || "-"
		}
	},
	afterModify: {
		width: 120,
		key: "afterModify",
		dataIndex: "afterModify",
		align: "center",
		title: newFormat("common.action_after"),
		render: (v: string) => {
			if (v && v.includes(";")) {
				const content = v.split(";").map((text, index) => <p key={index}>{text}</p>)
				const text = v.replaceAll(";", "")
				return (
					<Tooltip placement="top" title={content}>
						<Typography.Text style={{ maxWidth: 100 }} ellipsis>
							{text}
						</Typography.Text>
					</Tooltip>
				)
			}
			return v || "-"
		}
	},
	moduleName: {
		width: 120,
		key: "moduleName",
		dataIndex: "moduleName",
		align: "center",
		title: newFormat("common.action_module")
	},
	operatePage: {
		width: 120,
		key: "operatePage",
		dataIndex: "operatePage",
		align: "center",
		title: newFormat("common.action_page")
	},
	operateType: {
		width: 120,
		key: "operateType",
		dataIndex: "operateType",
		align: "center",
		title: newFormat("common.operation_type")
	},
	operateFunction: {
		width: 120,
		key: "operateFunction",
		dataIndex: "operateFunction",
		align: "center",
		title: newFormat("common.action_function")
	},
	operateObject: {
		width: 120,
		key: "operateObject",
		dataIndex: "operateObject",
		align: "center",
		title: newFormat("common.action_ob")
	},
	operateUserName: {
		width: 120,
		key: "operateUserName",
		dataIndex: "operateUserName",
		align: "center",
		title: newFormat("common.updateBy")
	},
	requestIp: {
		width: 120,
		key: "requestIp",
		dataIndex: "requestIp",
		align: "center",
		title: newFormat("common.updateByIP")
	},
	operateAfterParam: {
		width: 120,
		key: "operateAfterParam",
		dataIndex: "operateAfterParam",
		align: "center",
		title: newFormat("common.action_after"),
		render: (v: string) => {
			if (v && v.includes(";")) {
				const content = v.split(";").map((text, index) => <p key={index}>{text}</p>)
				const text = v.replaceAll(";", "")
				return (
					<Tooltip placement="top" title={content}>
						<Typography.Text style={{ maxWidth: 100 }} ellipsis>
							{text}
						</Typography.Text>
					</Tooltip>
				)
			}
			return v || "-"
		}
	},
	operateBeforeParam: {
		width: 120,
		key: "operateBeforeParam",
		dataIndex: "operateBeforeParam",
		align: "center",
		title: newFormat("common.action_before"),
		render: (v: string) => {
			if (v && v.includes(";")) {
				const content = v.split(";").map((text, index) => <p key={index}>{text}</p>)
				const text = v.replaceAll(";", "")
				return (
					<Tooltip placement="top" title={content}>
						<Typography.Text style={{ maxWidth: 100 }} ellipsis>
							{text}
						</Typography.Text>
					</Tooltip>
				)
			}
			return v || "-"
		}
	}
})

export default common
